//
//  YSOrdinaryOrderDetailFooterView.m
//  Yueshi
//
//  Created by Northwan on 15/10/23.
//  Copyright © 2015年 悦食中国. All rights reserved.
//  普通订单详情footer ，运费+代金券+总额

#import "YSOrdinaryOrderDetailFooterView.h"

#define TEXT_FONT 15

@interface YSOrdinaryOrderDetailFooterView()
@property (strong, nonatomic) UILabel *freightTipLabel;
@property (strong, nonatomic) UILabel *freightConditionLabel;
@property (strong, nonatomic) UILabel *freightLabel;
@property (strong, nonatomic) UILabel *voucherTipLabel;
@property (strong, nonatomic) UILabel *voucherLabel;
@property (strong, nonatomic) UIView *spliteView;
@property (strong, nonatomic) UILabel *totalPriceLabel;
@end

@implementation YSOrdinaryOrderDetailFooterView

-(instancetype)initWithFooterView:(YSOrder *)order voucherAmount:(float)voucherAmount{
    if(self = [super init]){
        [self setBackgroundColor:PUBLIC_CARD_BG];
        
        NSString *freightTipText =@"运费:";
        CGSize freightTipTextSize = [freightTipText sizeWithFont:SYS_FONT(TEXT_FONT)];
        UILabel *freightTipLabel = [[UILabel alloc]init];
        [freightTipLabel setText:freightTipText];
        [freightTipLabel setFont:SYS_FONT(TEXT_FONT)];
        [freightTipLabel setTextColor:ThemeColor];
        [freightTipLabel setFrame:CGRectMake(YSPublicXInset, 0, freightTipTextSize.width, freightTipTextSize.height)];
        [self addSubview:freightTipLabel];
        _freightTipLabel = freightTipLabel;
        
        //包邮条件
        NSString *freightConditionText = [NSString stringWithFormat:@"(满¥%ld元包邮)",order.satisfyFreight];
        CGSize freightConditionTextSize = [freightConditionText sizeWithFont:SYS_FONT(12)];
        UILabel *freightConditionLabel = [[UILabel alloc]init];
        [freightConditionLabel setFont:SYS_FONT(12)];
        freightConditionLabel.frame  = CGRectMake(CGRectGetMaxX(freightTipLabel.frame)+YSPublicXInset, CGRectGetMaxY(freightTipLabel.frame)-15, freightConditionTextSize.width, 12);
        [freightConditionLabel setTextColor:HEXColor(@"#9e9e9e")];
        [freightConditionLabel setText:freightConditionText];
        [self addSubview:freightConditionLabel];
        _freightConditionLabel = freightConditionLabel;
        
        //运费
        NSString *freightText = [NSString stringWithFormat:@"¥%ld",order.freight];
        CGSize freightTextSize = [freightText sizeWithFont:SYS_FONT(TEXT_FONT)];
        UILabel *freightLabel = [[UILabel alloc]init];
        freightLabel.frame = CGRectMake(SCREENW-YSPublicXInset-freightTextSize.width, CGRectGetMinY(freightTipLabel.frame), freightTextSize.width, TEXT_FONT);
        [freightLabel setFont:SYS_FONT(TEXT_FONT)];
        [freightLabel setTextColor:ThemeColor];
        [freightLabel setText:freightText];
        [self addSubview:freightLabel];
        _freightLabel = freightLabel;
        
        CGFloat spliteY = CGRectGetMaxY(_freightTipLabel.frame);
        
        if(voucherAmount){
            NSString *voucherTipText = @"代金券优惠:";
            CGSize voucherTipTextSize = [voucherTipText sizeWithFont:SYS_FONT(TEXT_FONT)];
            UILabel *voucherTipLabel = [[UILabel alloc]init];
            [voucherTipLabel setText:voucherTipText];
            [voucherTipLabel setFont:SYS_FONT(TEXT_FONT)];
            [voucherTipLabel setTextColor:ThemeColor];
            [voucherTipLabel setFrame:CGRectMake(YSPublicXInset, CGRectGetMaxY(_freightTipLabel.frame)+TEXT_FONT, voucherTipTextSize.width, voucherTipTextSize.height)];
            [self addSubview:voucherTipLabel];
            _voucherTipLabel = voucherTipLabel;
            
            //代金券减免价格
            NSString *voucherText = [NSString stringWithFormat:@"-¥%.1f",voucherAmount];
            CGSize voucherTextSize = [voucherText sizeWithFont:SYS_FONT(TEXT_FONT)];
            UILabel *voucherLabel = [[UILabel alloc]init];
            [voucherLabel setFont:SYS_FONT(TEXT_FONT)];
            voucherLabel.frame = CGRectMake(SCREENW-YSPublicXInset-voucherTextSize.width, CGRectGetMinY(voucherTipLabel.frame), voucherTextSize.width, TEXT_FONT);
            [voucherLabel setTextColor:ThemeColor];
            [voucherLabel setText:voucherText];
            [self addSubview:voucherLabel];
            _voucherLabel = voucherLabel;
            ;
            spliteY = CGRectGetMaxY(voucherTipLabel.frame);
        }
      
        UIView *spliteView = [[UIView alloc ]initWithFrame:CGRectMake(YSPublicXInset, spliteY+YSPublicXInset, SCREENW-YSPublicXInset*2, 0.5)];
        [spliteView setBackgroundColor:SPLIT_LINE_COLOR];
        [self addSubview:spliteView];
        _spliteView = spliteView;
        
        //总价
        NSString *totalPriceText = [NSString stringWithFormat:@"共%ld件商品   合计:¥%@",order.prodCount,order.orderPrice];
        CGSize totalPriceTextSize = [totalPriceText sizeWithFont:SYS_FONT(TEXT_FONT)];        UILabel *totalPriceLabel = [[UILabel alloc]init];
        [totalPriceLabel setFont:SYS_FONT(TEXT_FONT)];
        totalPriceLabel.frame = CGRectMake(SCREENW-YSPublicXInset-totalPriceTextSize.width, CGRectGetMaxY(spliteView.frame)+YSPublicXInset, totalPriceTextSize.width, TEXT_FONT);
        [totalPriceLabel setTextColor:publicTextColor];
        [totalPriceLabel setText:totalPriceText];
        [self addSubview:totalPriceLabel];
        _totalPriceLabel = totalPriceLabel;
        
        self.frame = CGRectMake(0, 0, SCREENW, CGRectGetMaxY(totalPriceLabel.frame)+YSPublicXInset);
    }
    return self;
}


@end
